package com.spring.sunflower.main.fragment;

import androidx.annotation.NonNull;

import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.spring.sunflower.R;
import com.spring.sunflower.base.BaseFragment;
import com.spring.sunflower.bean.ChatPeopleBean;
import com.spring.sunflower.main.MainContract;
import com.spring.sunflower.main.presenter.LivelyPresenter;
//import com.tencent.imsdk.TIMConversationType;
//import com.tencent.imsdk.conversation.Conversation;
//import com.tencent.imsdk.v2.V2TIMCallback;
//import com.tencent.imsdk.v2.V2TIMConversation;
//import com.tencent.imsdk.v2.V2TIMConversationListener;
//import com.tencent.imsdk.v2.V2TIMConversationResult;
//import com.tencent.imsdk.v2.V2TIMManager;
//import com.tencent.imsdk.v2.V2TIMMessage;
//import com.tencent.imsdk.v2.V2TIMValueCallback;
//import com.tencent.qcloud.tim.uikit.base.ITitleBarLayout;
//import com.tencent.qcloud.tim.uikit.base.IUIKitCallBack;
//import com.tencent.qcloud.tim.uikit.component.TitleBarLayout;
//import com.tencent.qcloud.tim.uikit.modules.chat.base.ChatInfo;
//import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationLayout;
//import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationListAdapter;
//import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationListLayout;
//import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationManagerKit;
//import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationProvider;
//import com.tencent.qcloud.tim.uikit.modules.conversation.base.ConversationInfo;
//import com.tencent.qcloud.tim.uikit.modules.conversation.interfaces.IConversationProvider;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by Kevin on 2021/5/28<br/>
 * <p>
 * Describe:<br/>
 */
public class MessageFragmentX extends BaseFragment<LivelyPresenter> implements MainContract.MessageView, OnLoadMoreListener, OnRefreshListener {

//    private ConversationLayout mConversationLayout;
//    private ConversationListAdapter mAdapter;
//    private ConversationManagerKit managerKit;

    @Override
    public int setLayoutResId() {
        return R.layout.fragmentx_message;
    }

    @Override
    public void initView() {
//        mConversationLayout = mView.findViewById(R.id.conversation_layout);
//        ConversationListLayout conversationList = mConversationLayout.getConversationList();
//        mAdapter = new ConversationListAdapter();
//        conversationList.setAdapter(mAdapter);
//        conversationList.setItemTopTextSize(16);
//        conversationList.setItemBottomTextSize(14);
//        conversationList.setItemDateTextSize(10);
//        conversationList.setItemAvatarRadius(30);
//        conversationList.disableItemUnreadDot(false);
//        TitleBarLayout titleBarLayout = mConversationLayout.findViewById(R.id.conversation_title);
//        titleBarLayout.setTitle("消息", ITitleBarLayout.POSITION.MIDDLE);
//        titleBarLayout.getLeftGroup().setVisibility(View.GONE);
//        titleBarLayout.getRightGroup().setVisibility(View.GONE);
//        titleBarLayout.setBackgroundColor(getColorX(R.color.colorPrimary));
//        titleBarLayout.getMiddleTitle().setTextColor(Color.WHITE);
//        conversationList.setOnItemClickListener(new ConversationListLayout.OnItemClickListener() {
//            @Override
//            public void onItemClick(View view, int position, ConversationInfo messageInfo) {
//                ChatInfo chatInfo = new ChatInfo();
//                chatInfo.setType(V2TIMConversation.V2TIM_C2C);
//                chatInfo.setId(messageInfo.getId());
//                chatInfo.setChatName(messageInfo.getTitle());
//                Intent intent = new Intent(mActivity, ChatXActivity.class);
//                intent.putExtra(Constant.CHAT_INFO, chatInfo);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                startActivity(intent);
//
//            }
//        });
//        managerKit = ConversationManagerKit.getInstance();
//        managerKit.loadConversation(new IUIKitCallBack() {
//            @Override
//            public void onSuccess(Object data) {
//                mAdapter.setDataProvider((ConversationProvider) data);
//            }
//
//            @Override
//            public void onError(String module, int errCode, String errMsg) {
//
//            }
//        });
//        tvTitle = mView.findViewById(R.id.tvTitle);
//        tvTitle.setText(getString(R.string.title_message));
//        refreshLayout = mView.findViewById(R.id.refreshLayout);
//        mRecyclerView = mView.findViewById(R.id.rvRecyclerView);
//        LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
//        mRecyclerView.setLayoutManager(layoutManager);
//        mAdapter = new MessageAdapter(R.layout.adapter_message_fragment, conversationList);
//        mRecyclerView.setAdapter(mAdapter);
//        refreshLayout.setOnLoadMoreListener(this);
//        refreshLayout.setOnRefreshListener(this);
//        V2TIMManager.getConversationManager().setConversationListener(new V2TIMConversationListener() {
//            @Override
//            public void onSyncServerStart() {
//                super.onSyncServerStart();
//            }
//
//            @Override
//            public void onSyncServerFinish() {
//                super.onSyncServerFinish();
//            }
//
//            @Override
//            public void onSyncServerFailed() {
//                super.onSyncServerFailed();
//            }
//
//            @Override
//            public void onNewConversation(List<V2TIMConversation> conversationList) {
//                super.onNewConversation(conversationList);
//                mAdapter.addData(conversationList);
//                printD("onNewConversation");
//            }
//
//            @Override
//            public void onConversationChanged(List<V2TIMConversation> conversationList) {
//                super.onConversationChanged(conversationList);
//                mAdapter.setNewInstance(conversationList);
//                printD("onConversationChanged");
//            }
//        });
//        mAdapter.setOnItemClickListener(new OnItemClickListener() {
//            @Override
//            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
//                V2TIMConversation v2TIMConversation = conversationList.get(position);
//                String conversationID = v2TIMConversation.getConversationID();
//                V2TIMMessage lastMessage = v2TIMConversation.getLastMessage();
//                long lastMessageTimestamp = lastMessage.getTimestamp();
//                String userID = v2TIMConversation.getUserID();
//                String showName = v2TIMConversation.getShowName();
//                String draftText = v2TIMConversation.getDraftText();
//                printD("conversationID=" + conversationID);
//                Intent intent = new Intent(mActivity, ChatActivity.class);
//                intent.putExtra(Constant.C2C_CONVERSATION_ID, conversationID);
//                intent.putExtra(Constant.C2C_USER_ID, userID);
//                intent.putExtra(Constant.C2C_SHOW_NAME, showName);
//                intent.putExtra(Constant.C2C_DRAFT_TEXT, draftText);
//                startActivity(intent);
//                V2TIMManager.getMessageManager().markC2CMessageAsRead(userID, new V2TIMCallback() {
//                    @Override
//                    public void onError(int code, String desc) {
//
//                    }
//
//                    @Override
//                    public void onSuccess() {
//
//                    }
//                });
//            }
//        });
    }

    @Override
    public void initData() {
//        V2TIMManager.getConversationManager().getConversationList(0, 100, new V2TIMValueCallback<V2TIMConversationResult>() {
//            @Override
//            public void onError(int i, String s) {
//
//            }
//
//            @Override
//            public void onSuccess(V2TIMConversationResult v2TIMConversationResult) {
//                long nextSeq = v2TIMConversationResult.getNextSeq();
//                boolean finished = v2TIMConversationResult.isFinished();
//                List<V2TIMConversation> conversationList = v2TIMConversationResult.getConversationList();
////                conversationList.get(0).get
//                mAdapter.addData(conversationList);
//            }
//        });
        getConversationListX();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    public void getConversationListX() {
    }

    @Override
    public void initListener() {

    }

    @Override
    public void loadData() {

    }

    @Override
    public LivelyPresenter setPresenter() {
        return null;
    }

    @Override
    public void onLoadMore(@NonNull @NotNull RefreshLayout refreshLayout) {

    }

    @Override
    public void onRefresh(@NonNull @NotNull RefreshLayout refreshLayout) {
        getConversationListX();
    }


    @Override
    public void showChatPeople(List<ChatPeopleBean.DatasBean> data, boolean b) {

    }
}
